from tools_algorithm import *


class Solution:
    def maximumSubsequenceCount(self, text: str, pattern: str) -> int:
        a, b = pattern
        ca = cb = 0
        ans = 0
        for v in text:
            if v == a:
                ca += 1
            elif v == b:
                ans += ca
                cb += 1
        return ans + max(ca, cb) if a != b else (1 + ca) * ca // 2
